package com.d2rv.model;

import com.d2rv.offscreen.OffScreen3D;
import java.io.File;
import javax.media.opengl.GL;
import processing.core.PApplet;
import processing.core.PVector;
import saito.objloader.OBJModel;
import saito.objloader.OBJModelLite;

/**
 * Describes the Goal model
 *
 * @author Darrieutort A., Dupouy A., Rossignol L., Van Poucke A.
 */
public class GoalModel extends ObjModel {

    private OBJModelLite model_1;
    private OBJModelLite model_2;
    private OBJModelLite model_3;

    /**
     * Default constructor
     *
     * @param parent the current application
     * @param path the path of the obj model
     */
    public GoalModel(PApplet parent, String path) {
        super(parent, path, new PVector(0, 0, 0));
        OBJModel tmp_1 = new OBJModel(parent, parent.dataPath("models" + File.separator + "course_1" + File.separator + "course_1.obj"), "relative", processing.opengl.PGraphicsOpenGL.TRIANGLES);
        this.model_1 = tmp_1.setupGLCreateLite();
        OBJModel tmp_2 = new OBJModel(parent, parent.dataPath("models" + File.separator + "course_2" + File.separator + "course_2.obj"), "relative", processing.opengl.PGraphicsOpenGL.TRIANGLES);
        this.model_2 = tmp_2.setupGLCreateLite();
        OBJModel tmp_3 = new OBJModel(parent, parent.dataPath("models" + File.separator + "course_3" + File.separator + "course_3.obj"), "relative", processing.opengl.PGraphicsOpenGL.TRIANGLES);
        this.model_3 = tmp_3.setupGLCreateLite();
    }

    /**
     * Contains the instructions to draw the model
     *
     * @param parent the current offscreen
     */
    public void draw(OffScreen3D parent) {
        GL gl = parent.beginGL();
        parent.scale(this.scale.x, this.scale.y, this.scale.z);
        this.model.drawGL(gl);
        parent.endGL();
    }

    /**
     * Allows to change the model of the sphere used in the scene
     *
     * @param n indicates the type of sphere
     */
    public void changeSphere(int n) {
        if (n == 2) {
            this.model = this.model_2;
        } else if (n == 3) {
            this.model = this.model_3;
        } else {
            this.model = this.model_1;
        }
    }
}
